<?php
session_start();

header('Content-Type: text/plain; charset=utf-8'); 

require("../fantasmatakia/pektis.php");
require("../lib/standard.php");

$globals->check_pektis();

if (iparxi_partida()) {
	die(0);
}

$query = "INSERT INTO `partida` (`pektis1`, `poll`) VALUES ('" .
	$globals->pektis->login . "', NOW())";
@mysqli_query($globals->db, $query);

if (mysqli_affected_rows($globals->db) == 1) {
	die(0);
}

die("SQL error: " . mysqli_error($globals->db));

function iparxi_partida() {
	global $globals;

	$query = "UPDATE `partida` SET `poll` = NOW() WHERE " .
		"(`telos` IS NULL) AND ((`pektis1` = '" . $globals->pektis->login .
		"') OR (`pektis2` = '" . $globals->pektis->login . "'))";
	@mysqli_query($globals->db, $query);

	return (mysqli_affected_rows($globals->db) >= 1);
}
	

?>
